<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE HTML>
<html>
<head>
    <title>Sign Up</title>
    <%@ include file="common/bootstrap.jspf" %>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=GLh0FXPyskLbzIDjt5gPQx4skGBRdlCL"></script>
    <script type="application/x-javascript">
        addEventListener("load", function () {
            setTimeout(hideURLbar, 0);
        }, false);
        function hideURLbar() {
            window.scrollTo(0, 1);
        }
        new WOW().init();
    </script>
    <style type="text/css">
        #username + span, #rePassword + span {
            color: red;
        }

        .show {
            display: block;
        }

        .display_none {
            display: none;
        }

    </style>

</head>

<body class="sign-in-up">
<section>
    <div id="page-wrapper" class="sign-in-wrapper">
        <div class="graphs">
            <form id="register" name="register" action="insertUser" method="post">
                <div class="sign-up">
                    <h3>智慧验车</h3>

                    <p class="creating"></p>
                    <h5>登录信息</h5>

                    <div class="sign-u">
                        <div class="form-group">
                            <label for="username">用户名*</label>
                            <input type="text" class="form-control" name="username" id="username" placeholder="请输入用户名"
                                   required="required"/>
                            <span class="display_none">用户名已存在</span>
                        </div>
                    </div>
                    <div class="sign-u">
                        <div class="form-group">
                            <label for="password">密码*</label>
                            <input type="password" class="form-control" name="password" id="password" placeholder="请输入密码"
                                   required="required"/>
                        </div>
                    </div>
                    <div class="sign-u">
                        <div class="form-group">
                            <label for="password">确认密码* </label>
                            <input type="password" class="form-control" name="rePassword" id="rePassword"
                                   placeholder="请再次输入密码" required="required"/><span class="display_none">密码不一致!</span>
                        </div>
                    </div>

                    <h6>商铺信息</h6>

                    <div class="sign-u">
                        <div class="form-group">
                            <label for="password">商铺名称* </label>
                            <input type="text" class="form-control" name="name" id="name" placeholder="请输入商铺名称"
                                   required="required"/>
                        </div>
                    </div>
                    <div class="sign-u">
                        <div class="form-group">
                            <label for="password">经度* </label>
                            <input type="text" class="form-control" name="longitude" id="longitude" placeholder="经度"
                                   required="required" readonly/>
                        </div>
                    </div>
                    <div class="sign-u">
                        <div class="form-group">
                            <label for="password">纬度* </label>
                            <input type="text" class="form-control" name="latitude" id="latitude" placeholder="纬度"
                                   required="required" readonly/>
                        </div>
                    </div>
                    <div class="sign-u">
                        <div class="form-group">
                            <label for="password">商铺地址* </label>
                            <input type="text" class="form-control" name="address" id="address" placeholder="请输入商铺地址"
                                   required="required"/>
                            <span class="glyphicon glyphicon-search" id="open">点此查看地图 </span>
                        </div>
                    </div>
                    <div id='allmap' style='width: 50%; height: 50%; position: absolute; display: none'></div>  
                    <div class="sign-u">
                        <div class="form-group">
                            <label for="password">所在城市* </label>
                            <input type="text" class="form-control" name="city" id="city" placeholder="请输入城市"
                                   required="required"/>
                        </div>
                    </div>
                    <div class="sign-u">
                        <div class="form-group">
                            <label for="password">每日最大订单量* </label>
                            <input type="text" class="form-control" name="maxOrderPerDay" id="maxOrderPerDay"
                                   placeholder="请输入每日最大订单量" required="required"/>
                        </div>
                    </div>
                    <div class="sign-u">
                        <div class="form-group">
                            <label for="password">注册密钥* </label>
                            <input type="text" class="form-control" name="token" id="token"
                                   placeholder="请输入密钥" required="required"/>
                        </div>
                    </div>
                    <div class="sub_home">
                        <div class="sub_home_left">
                            <input type="submit" value="注册">
                        </div>
                        <div class="sub_home_right">
                            <p><a href="toLogin">返回登录页</a></p>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <footer>
        <p>Copyright &copy; 2015.Company name All rights reserved.</p>
    </footer>
</section>

<script>
    $("#username").blur(function () {
        var _this = $(this);
        if (_this.val() == "") {
            return;
        }
        $.ajax({
            type: "POST",
            url: "getUserOnly",
            data: {
                username: $(this).val()
            },
            success: function (data) {
                if (data == 1) {
                    $('#username + span').removeClass('display_none');
                    $('#username + span').addClass('show');
                }else{
                    $('#username + span').removeClass('show');
                    $('#username + span').addClass('display_none');
                }
            },
            error: function () {
                alert("查询失败")
            }
        });
    })

    $("#rePassword, #password").blur(function () {
        var _this = $(this);
        var pass = $("#password").val();
        var repass = $("#rePassword").val();
        if (pass && repass && pass != repass) {
            $('#rePassword + span').removeClass('display_none');
            $('#rePassword + span').addClass('show');
        } else {
            $('#rePassword + span').removeClass('show');
            $('#rePassword + span').addClass('display_none');
        }

    })
    
    
    function validate() {  
        var address = document.getElementsByName('address')[0].value;  
        if (isNull(address)) {  
            alert('请选择地址');  
            return false;  
        }  
        return true;  
    }  
  
    //判断是否是空  
    function isNull(a) {  
        return (a == '' || typeof(a) == 'undefined' || a == null) ? true : false;  
    }  
  
    document.getElementById('open').onclick = function () {  
        if (document.getElementById('allmap').style.display == 'none') {  
            document.getElementById('allmap').style.display = 'block';  
        } else {  
            document.getElementById('allmap').style.display = 'none';  
        }  
    }  
  
    var map = new BMap.Map("allmap");  
    map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);  // 初始化地图,设置中心点坐标和地图级别
	map.addControl(new BMap.MapTypeControl());   //添加地图类型控件
	map.setCurrentCity("北京");          // 设置地图显示的城市 此项是必须设置的
    var geoc = new BMap.Geocoder();   //地址解析对象  
    var markersArray = [];  
    var geolocation = new BMap.Geolocation();  
  
    geolocation.getCurrentPosition(function (r) {  
        if (this.getStatus() == BMAP_STATUS_SUCCESS) {  
            var mk = new BMap.Marker(r.point);  
            map.addOverlay(mk);  
            map.panTo(r.point);  
            map.enableScrollWheelZoom(true);  
        }  
        else {  
            alert('failed' + this.getStatus());  
        }  
    }, {enableHighAccuracy: true})  
    map.addEventListener("click", showInfo);  
  
  
    //清除标识  
    function clearOverlays() {  
        if (markersArray) {  
            for (i in markersArray) {  
                map.removeOverlay(markersArray[i])  
            }  
        }  
    }  
    //地图上标注  
    function addMarker(point) {  
        var marker = new BMap.Marker(point);  
        markersArray.push(marker);  
        clearOverlays();  
        map.addOverlay(marker);  
    }  
    //点击地图时间处理  
    function showInfo(e) {  
        document.getElementById('longitude').value = e.point.lng;  
        document.getElementById('latitude').value =  e.point.lat;  
        geoc.getLocation(e.point, function (rs) {  
            var addComp = rs.addressComponents;  
            var address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;  
            document.getElementById('allmap').style.display = 'none';  
            document.getElementById('address').value = address;  
        });  
        addMarker(e.point);  
    }  
</script>
</body>
</html>